package com.kaesar.thread_ressmix.atomic;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: chengk
 * @Date: 2021/8/31 12:43 上午
 */
public class FieldUpdaterTest2 {
    public static void main(String[] args) throws InterruptedException {
        Account2 account = new Account2(0); // 初始金额为0

        List<Thread> list = new ArrayList<>();
        for (int i = 0; i < 100000; i++) {
            Thread t = new Thread(new Task(account));
            list.add(t);
            t.start();
        }

        for (Thread thread : list) {
            thread.join();
        }

        System.out.println(account.toString());
    }

    private static class Task implements Runnable {
        private Account2 account;

        Task(Account2 account) {
            this.account = account;
        }

        @Override
        public void run() {
            account.increMoney();
        }
    }
}
